using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace IGGCore
{
    /// <summary>
    /// The list of games happening on the same day
    /// </summary>
    public class GameList
    {
        private List<Game> m_gameTable = new List<Game>();
        private List<Game> m_gameTableSorted = new List<Game>();
        private List<Game> m_highestRatioTable = new List<Game>();

        private int highestRatio = -9999;

        public List<Game> Games
        {
            get { return m_gameTable; }
        }

        public List<Game> HighestRatioGames
        {
            get { return m_highestRatioTable; }
        }

        public List<Game> SortedGames
        {
            get { return m_gameTableSorted; }
        }

        /// <summary>
        /// Get the highest rated game
        /// </summary>
        public Game GetHighestRatioGame()
        {
            if (m_highestRatioTable.Count == 1)
            {
                return m_highestRatioTable[0];
            }
            else
            {
                Random rnd = new Random();
                return m_highestRatioTable[rnd.Next(m_highestRatioTable.Count)];
            }
        }

        /// <summary>
        /// Add a game to the list
        /// </summary>
        /// <param name="game"></param>
        public void AddGame(Game game)
        {
            m_gameTable.Add(game);
            m_gameTableSorted.Add(game);
            m_gameTableSorted.Sort();

            if (game.Ratio == highestRatio)
            {
                m_highestRatioTable.Add(game);
            }
            else if (game.Ratio > highestRatio)
            {
                highestRatio = game.Ratio;
                m_highestRatioTable.Clear();
                m_highestRatioTable.Add(game);
            }
        }

        /// <summary>
        /// Clear the list and reset ratio tables
        /// </summary>
        public void ClearList()
        {
            highestRatio = -9999;
            m_gameTable.Clear();
            m_highestRatioTable.Clear();
        }
    }
}
